﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class crm_individuals_download : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            string filename = "";
            if (!string.IsNullOrEmpty(Request.Params["filename"]))
            {
                filename = Request.Params["filename"];
            }
            int start = filename.LastIndexOf('.');            
           
            string type = filename.Substring(start, 3).ToLower();
            if (type.Equals("pdf"))
            {
                type = "application/pdf";
            }
            else
            {
                type = "image/jpeg";
            }
            // jpg image/jpeg  pdf application/pdf
            Response.Clear();
            Response.ContentType = type;
            Response.AddHeader("Content-Disposition", "attachment;FileName=" + HttpUtility.UrlEncode(filename, System.Text.Encoding.UTF8));
            Response.WriteFile("/pub/crm/attchment/" + filename);
            Response.End();
        }

    }
}
